package com.answer.model.enums;

import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

/**
 * 文件上传业务类型枚举
 */
@Getter
public enum FileUploadEnum {

    USER_AVATAR("用户头像", "user_avatar"),
    APP_ICON("应用图标", "app_icon"),
    SCORING_RESULT_PICTURE("评分结果图片", "scoring_result_picture");

    private final String text;

    private final String value;

    FileUploadEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value 枚举的值
     * @return 对应的枚举常量，如果找不到则返回null
     */
    public static FileUploadEnum getEnumByValue(String value) {
        // 检查参数是否为空，为空则直接返回null
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        // 遍历枚举常量，查找匹配的值
        for (FileUploadEnum anEnum : FileUploadEnum.values()) {
            // 如果找到匹配的值，则返回对应的枚举常量
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        // 遍历完所有枚举常量仍未找到匹配的值，返回null
        return null;
    }
}
